home *** CD-ROM | disk | FTP | other *** search
/ The ZX Files 3 / ZX Files 3 (Disk 3 of 3).adf / 125 / 125
Text File  |  1978-01-28  |  61KB  |  1,945 lines

  1.  
  2. [Note from transcriber: I left out the index and page numbers from the
  3. contents. I also couldn't reproduces the figures, but I left any
  4. references to them in the text.
  5.  
  6.  
  7. SINCLAIR
  8.  
  9. ZX INTERFACE
  10.  
  11. and
  12.  
  13. ZX MICRODRIVE
  14.  
  15. Designed and prepared by Cambridge Communication Limited
  16.  
  17.  
  18. Note
  19. The name ZX Microdrive and ZX Interface 1 are trademarks of
  20. Sinclair Research Limited
  21. Stanhope Road
  22. Camberley
  23. Surrey
  24. GU15 3PS
  25. Tel: Camberley (0276) 685311
  26.  
  27. First Edition 1983
  28. (c) Sinclair Research Limited
  29.  
  30.  
  31. THE ZX INTERFACE 1...
  32. incorporates the three functions of Microdrive controller, local area
  33. network and RS232 Interface. Connect it to your Spectrum and you can
  34. control up to eight Microdrives, communicate with other computers and
  35. drive a wide range of printers.
  36.  
  37. THE ZX MICRODRIVE...
  38. gives you fast access to a large memory. Each Microdrive can hold up
  39. to 100k bytes using a single interchangeable cartridge.
  40.  
  41. THIS MANUAL...
  42. introduces the idea of using BASIC as an operating system as well as a
  43. programming language. This way, BASIC can be used to set up
  44. communication links, to send and receive data along them and to
  45. manipulate files. This adds enormously to its power to perform tasks
  46. in which:
  47.  
  48. - data is stored and retrieved,
  49.  
  50. - data and programs are sent to peripherals,
  51.  
  52. - communication links are established with other Spectrum computers or
  53.   with other types of computer.
  54.  
  55. The combined use of BASIC as an operating system and a programming
  56. language gives it a power and flexibility, and also an ease of use, to
  57. be found in few large computers.
  58.  
  59. You should read the chapters on the Microdrive even if you have not
  60. bought one, since they introduce various concepts (about channels and
  61. streams and their use) which you will need to understand.
  62.  
  63. This manual should only be read after you have familiarised yourself
  64. with the ZX Spectrum Introduction booklet and with chapters 1 to 22 of
  65. the BASIC programming manual.
  66.  
  67.  
  68. CONTENTS
  69.  
  70. Chapter 1       Setting up your ZX Interface 1
  71.  
  72. Chapter 2       Setting up your Microdrive
  73.                  handling cartridges
  74.                  protecting programs and data stored in cartridges
  75.                  the cartridge lifespan
  76.  
  77. Chapter 3       Starting with your Microdrive
  78.                  auto-run
  79.                  the catalogue
  80.                  loading programs
  81.  
  82. Chapter 4       Programs and the Microdrive
  83.                  saving, verifying, loading and merging programs
  84.                  erasing programs
  85.                  formatting and naming blank cartridges
  86.                  setting up your own auto-run facility
  87.  
  88. Chapter 5       Data, channels and streams
  89.  
  90. Chapter 6       Data and the Microdrive
  91.                  opening and naming a data files
  92.                  entering data
  93.                  closing a file
  94.                  reading back from a file
  95.                  notes on PRINT and INPUT - separators
  96.                                           - changing streams
  97.                                           - setting colours
  98.                  reading the file catalogue
  99.                  protecting a file
  100.                  extending a file
  101.  
  102. Chapter 7       The Local Are Network
  103.                  setting up a network
  104.                  programs and the network
  105.                  data and the network
  106.                  broadcasting
  107.  
  108. Chapter 8       Using the RS232 Interface
  109.                  connecting the peripherals to the RS232 Interface
  110.                  t and b channels
  111.                  the t channel
  112.                  the b channel
  113.                  sending control codes
  114.  
  115. Chapter 9       The MOVE statement
  116.                  the printer server program
  117.  
  118. Appendix 1      The net game
  119.  
  120. Appendix 2      System variables
  121.  
  122. Appendix 3      Microdrive and network channels
  123.  
  124. Appendix 4      RS232 connections
  125.  
  126. Appendix 5      Reports
  127.  
  128. Appendix 6      The extended BASIC
  129.  
  130.  
  131. Chapter 1
  132.  
  133. SETTING UP YOUR ZX INTERFACE 1
  134.  
  135.  
  136. Unpacking the ZX Interface 1 you will have found:
  137.  
  138. - this booklet,
  139.  
  140. - the Interface itself (with two captive screws on the underside),
  141.  
  142. - a ribbon cable about 8cms long (for connecting the Interface to a
  143.   Microdrive),
  144.  
  145. - a lead with a jack plug at either end (for setting up a network).
  146.  
  147. To attach the Interface to your computer you should:
  148.  
  149. 1. Unplug the computer.
  150.  
  151. 2. Disconnect the computer from the peripherals.
  152.  
  153. 3. Using a Posidrive screwdriver remove the the two screws on the
  154.    underside of the computer, as shown in the diagram below. (You will
  155.    only need these screws again if you later disconnect the Interface
  156.    from the computer.)
  157.  
  158. 4. Push the Interface edge connector firmly into the socket at the back
  159.    of the computer.
  160.  
  161. 5. Screw the Interface to the underside of the computer using the two
  162.    captive screws supplied.
  163.  
  164. You can now reconnect the computer to its peripherals, and plug it in.
  165.  
  166. The diagram below shows what the various sockets on the Interface are
  167. for.
  168.  
  169. You can now either
  170.  
  171. - set up a Microdrive,
  172.  
  173. or
  174.  
  175. - set up a network,
  176.  
  177. or
  178.  
  179. - connect the Interface to an RS232 peripheral.
  180.  
  181.  
  182. Chapter 2
  183.  
  184. SETTING UP YOUR MICRODRIVE
  185.  
  186. Unpacking the Microdrive you will have found:
  187.  
  188. - the Microdrive itself,
  189.  
  190. - an electrical connector (for connecting this Microdrive to another
  191.   one).
  192.  
  193. - a pre-recorded demonstration cartridge.
  194.  
  195. To attach the Microdrive to the Interface, push one end of the ribbon
  196. cable (supplied with the Interface) firmly into the socket on the
  197. side of the Interface. Then push the other end of the cable into the
  198. socket in the side of the Microdrive.
  199.  
  200. If you have several Microdrives, the second one can be connected to
  201. the first as follows.
  202.  
  203. 1. Disconnect the Microdrive from the computer.
  204.  
  205. 2. Turn both Microdrives upside down. You will find that each has a
  206.    bracket screwed to the underside.
  207.  
  208. 3. Unscrew and remove both brackets.
  209.  
  210. 3. Turn the Microdrives the right way up again.
  211.  
  212. 5. Push one of the electrical connectors firmly into the socket on the
  213.    side of one of your Microdrives (as shown below).
  214.  
  215. 6. Push the second Microdrive up against the first, so that the other
  216.    end of the electrical connector pushes into the socket on the side
  217.    of the second Microdrive.
  218.  
  219. 7. Carefully turning the Microdrives over again, screw back one of the
  220.    two brackets - but this time so that it links up the two
  221.    Microdrives. (The remaining electrical connector, bracket and
  222.    screws can now be kept for linking up a further Microdrive.)
  223.  
  224. 8. Turn the Microdrives the right way up again, and reconnect the one
  225.    on the right-hand end to the computer.
  226.  
  227. Note that the Microdrive nearest the computer is always known as
  228. Microdrive 1, and the next along is Microdrive 2, and so on.
  229.  
  230. Notice also that on the front of each Microdrive there is a
  231. light. This will come on whenever the Microdrive is running.
  232.  
  233.  
  234. Handling cartridges
  235.  
  236. Every cartridge comes in a protective box; and should always be kept
  237. in its box when not in use.
  238.  
  239. When you take a cartridge out of its box (being careful not to touch
  240. the tape itself) you will see that it has a label on the top and
  241. another on the side.
  242.  
  243. Push the cartridge firmly into the slot in the front of the
  244. Microdrive, making sure that the label on the side faces upwards. This
  245. will leave the top of the cartridge projecting by about 1/2cm. The
  246. Microdrive and cartridge are now ready to be used.
  247.  
  248. When you have finished using the cartridge, pull it carefully out of
  249. the Microdrive, and replace it immediately in its box. But remember...
  250.  
  251. NEVER TAKE THE CARTRIDGE OUT OF THE MICRODRIVE WHILE THE MICRODRIVE
  252. LIGHT IS ON.
  253.  
  254. NEVER SWITCH THE POWER ON OR OFF WHILE A CARTRIDGE IS IN THE MICRODRIVE.
  255.  
  256.  
  257. Protecting programs and data stored in cartridges
  258.  
  259. If you wish to protect the programs and data stored in a cartridge
  260. (that is, prevent them from being over-written or erased) then you
  261. should snap off the plastic tab from the side of the cartridge, as
  262. shown below.
  263.  
  264. (As with a cassette, you can reverse this effect by sticking some tape
  265. over the place where the tab has been removed.)
  266.  
  267.  
  268. The cartridge lifespan
  269.  
  270. Microdrive cartridges will not last forever, and will eventually need
  271. to be replaced. The symptom of an ageing cartridge is that the
  272. computer will take longer and longer to find a program or file before
  273. loading it. So it is a good idea to keep back-up copies of important
  274. programs and files either on another cartridge, or on a cassette.
  275.  
  276.  
  277. Chapter 3
  278.  
  279. STARTING WITH YOUR MICRODRIVE
  280.  
  281.  
  282. Auto-run
  283.  
  284. Now that you have set up your ZX Interface 1 and your Microdrive, you
  285. will want to know what programs are waiting for you on the
  286. demonstration cartridge. So, insert the cartridge into the Microdrive
  287. (or, if you have several Microdrives, into Microdrive 1), and enter:
  288.  
  289.         NEW
  290.  
  291. followed by:
  292.  
  293.         RUN (and ENTER)
  294.  
  295. This will automatically load and run the first program on the
  296. cartridge. When you have finished watching this program, read on.
  297.  
  298.  
  299. The catalogue
  300.  
  301. To find out what other programs are stored in the demonstration
  302. cartridge, enter the CATalogue statement:
  303.  
  304.         CAT 1
  305.             |
  306.         1 identifies the number of the
  307.         Microdrive you are using
  308.  
  309. In about seven seconds the television screen will display:
  310.  
  311. - the name of the cartridge
  312.  
  313. - an alphabetical catalogue of the names of all the files stored in
  314.   the cartridge,
  315.  
  316. - the amount of memory left in the cartridge (in kilobytes).
  317.  
  318.  
  319. Loading programs
  320.  
  321. The next thing to do is LOAD whichever program you would like to see
  322. next. So, first choose your program, then enter:
  323.  
  324.         LOAD *"m";1;"name"
  325.              |    |   \---------------\
  326.    the star tells \ "m";1; identifies  here you enter the name of
  327.    the computer     which Microdrive   the program you have chosen
  328.    that you are     you are using
  329.    using a 
  330.    Microdrive,
  331.    not an
  332.    ordinary
  333.    cassette
  334.    recorder
  335.  
  336. After a short pause, the screen will display the OK message (though
  337. not the name of the program). You can now run the program.
  338.  
  339.  
  340. Chapter 4
  341.  
  342. PROGRAMS AND THE MICRODRIVE
  343.  
  344.  
  345. Saving, verifying, loading and merging programs
  346.  
  347. In the ZX Spectrum Introduction booklet you found out how to SAVE
  348. programs on a cassette tape. Saving programs in cartridges is just as
  349. easy. Here again is a program called Square, much like the one in the
  350. Introduction booklet:
  351.  
  352.         10 REM Squares
  353.         20 FOR n=1 TO 10
  354.         30 PRINT n,n*n
  355.         40 NEXT n
  356.  
  357. To SAVE this on a cassette tape you would enter:
  358.  
  359.         SAVE "Squares"
  360.  
  361. To SAVE it in the cartridge in Microdrive 1, you enter:
  362.  
  363.         SAVE *"m";1;"Squares"
  364.  
  365. After about six seconds the border will flash, and the program will be
  366. saved. Try it and see.
  367.  
  368. (The names of the programs stored in a cartridges, like those of
  369. programs stored on a cassette tape, can be up to ten characters long.)
  370.  
  371. As you would expect, you can now check that the program has been saved
  372. by entering:
  373.  
  374.         VERIFY *"m";1;"Squares"
  375.  
  376. The screen will then display the OK message.
  377.  
  378. You can now LOAD the program Squares by entering:
  379.  
  380.         NEW
  381.  
  382. followed by:
  383.  
  384.         LOAD *"m";1;"Squares"
  385.  
  386. then:
  387.  
  388.         ENTER
  389.  
  390. Next, to make the program run automatically, try entering:
  391.  
  392.         SAVE *"m";1;"Squares 2" LINE 10
  393.  
  394. then:
  395.  
  396.         NEW
  397.  
  398. and then:
  399.  
  400.         LOAD *"m";1;"Squares 2"
  401.  
  402. Programs can also be merged using a Microdrive. Enter:
  403.  
  404.         NEW
  405.  
  406. followed by:
  407.  
  408.         100 REM more Squares
  409.         110 FOR n=11 TO 20
  410.         120 PRINT n,n*n
  411.         130 NEXT n
  412.  
  413. And now enter:
  414.  
  415.         MERGE *"m";1;"Squares"
  416.  
  417. then:
  418.  
  419.         ENTER
  420.  
  421. The program Squares will be added to the listing.
  422.  
  423. In short, as you have probably already realised, all the syntax used
  424. within an ordinary cassette interface (explained in chapter 20 of the
  425. BASIC programming manual) applies also to the Microdrive.
  426.  
  427.  
  428. Erasing programs
  429.  
  430. Suppose you have just finished with the program Squares. To erase it,
  431. enter:
  432.  
  433.         ERASE "m";1;"Squares"
  434.  
  435. (As before "m";1 simply indicates which Microdrive you are using.)
  436.  
  437. During the ERASE statement the border will flash.
  438.  
  439. If you BREAK while saving a program then you will have an unclosed file
  440. in the cartridge. You cannot LOAD an unclosed files, and an attempt to
  441. do so will give the report 'file not found'. The ERASE Statement can
  442. delete an unclosed file, but will take about thirty seconds to do so
  443. because the computer checks the cartridge several times to make sure
  444. that the file has no end.
  445.  
  446.  
  447. Formatting and naming blank cartridges
  448.  
  449. If you have bought a blank cartridge, before you can use it you
  450. must insert it into a Microdrive (say, into Microdrive 1) and enter
  451. this:
  452.  
  453.         FORMAT "m";1;"name"
  454.                  |        \
  455.         "m";1 identifies    enter here whatever name you wish
  456.         the Microdrive      to appear in the cartridge
  457.         you are using       catalogue. It can be up to 10
  458.         (in this case       characters in length.
  459.         number 1)
  460.  
  461. The computer takes about thirty seconds to format a cartridge. During
  462. this time the border will first flash, then clear, then flash again,
  463. and finally display the OK message. What the computer is doing is
  464. identifying any areas that cannot be written to or read from and
  465. marking them to be avoided.
  466.  
  467. Formatting need never be repeated. Note, by the way, that when you
  468. format a cartridge, any information it contains will be erased. So, if
  469. you have bought several Microdrives, you can FORMAT your spare
  470. demonstration cartridges and use them as blank cartridges.
  471.  
  472. Next type:
  473.  
  474.         CAT 1
  475.             |
  476.         1 identifies the number of
  477.         the Microdrive you are using
  478.  
  479. In a few seconds, the television screen will display the cartridge's
  480. name and its capacity. The capacity will vary from cartridge to
  481. cartridge, but it should never be less than 85 kilobytes.
  482.  
  483.  
  484. Setting up your own auto-run facility
  485.  
  486. Earlier, you used the auto-run facility on the demonstration
  487. cartridge. If you have a program that you often use, you can set up
  488. your own auto-run facility, so as to avoid repeatedly having to type
  489. LOAD and RUN statements. These are the rules to follow:
  490.  
  491. - the program must be called 'run';
  492.  
  493. - the cartridge must be used in Microdrive 1;
  494.  
  495. - the facility must be used either immediately after switching on, or
  496.   immediately after entering NEW.
  497.  
  498. So, enter the required program, followed by:
  499.  
  500.         10 SAVE *"m";1;"run" LINE number
  501.                          |          \
  502.            the name 'run' must be    enter here the
  503.            typed out in full. Do     appropriate line number
  504.            not just press the
  505.            RUN key
  506.  
  507. Now enter:
  508.  
  509.         NEW
  510.  
  511. followed by:
  512.  
  513.         RUN (and ENTER)
  514.          |
  515.         enter the keyword,
  516.         not the file name
  517.  
  518. Note, however that the MERGE statement does not work with any program
  519. saved using SAVE *...LINE... statement. (This is so as to protect such
  520. programs.) An attempt to MERGE will give the report 'Merge error'.
  521.  
  522.  
  523. Chapter 5
  524.  
  525. DATA, CHANNELS AND STREAMS
  526.  
  527.  
  528. As you know, a program is a set of operations which is executed when
  529. you type RUN. Data, on the other hand, is any collection of letters,
  530. numbers or symbols on which a program might operate. An example is the
  531. numbers 1 to 10 with their squares.
  532.  
  533. Data can be sent to, and come from, various parts of a computer
  534. system. Such parts are know as channels. The channels you can send
  535. data to are:
  536.  
  537. - your screen,
  538.  
  539. - a ZX Printer,
  540.  
  541. - a Microdrive file, to store it,
  542.  
  543. - another ZX Spectrum computer, if both computers are on a network,
  544.  
  545. - the RS232 Interface and from there, for example, to a modem or
  546.   printer.
  547.  
  548. And the channels from which data can come are:
  549.  
  550. - the keyboard
  551.  
  552. - a Microdrive file,
  553.  
  554. - another ZX Spectrum computer, if both computers are on a network,
  555.  
  556. - the RS232 Interface, a modem or a terminal.
  557.  
  558. The routes along which the data flows to and from these channels are
  559. known as streams. In the Spectrum computer system the number of these
  560. streams is fixed at sixteen. They are numbered from 0 to 15, and
  561. stream numbers are always preceded by the sign #.
  562.  
  563. Four of these streams come already linked to channels:
  564.  
  565.         stream #0\  output data to the lower part of the television
  566.                   | screen and input from the keyboard;
  567.         stream #1/
  568.  
  569.         stream #2 outputs to the upper part of the screen, but cannot
  570.                   input;
  571.  
  572.         stream #3 outputs via the ZX Printer; but cannot input.
  573.  
  574. Every stream that produces input or output uses one of these streams
  575. automatically. For example, the PRINT statement uses stream #2, and
  576. the LPRINT statement uses stream #3. So, if you enter:
  577.  
  578.         PRINT "This is a Spectrum computer"
  579.  
  580. it is, in fact, shorthand for:
  581.  
  582.         PRINT #2; "This is a Spectrum computer"
  583.  
  584. Try entering both, and see.
  585.  
  586. You can, however, make any statement use a different stream by keying #
  587. followed by the new stream number. Try entering:
  588.  
  589.         LPRINT #2;"This is a Spectrum computer"
  590.  
  591. Instead of being printed by the ZX Printer, this line too appears on
  592. the screen.
  593.  
  594. But as well as using the established stream-channels, you can create
  595. some of your own. Streams #4 to #15 are free for this purpose; and
  596. there are various channel specifiers which enable you to indicate
  597. which peripheral you require. Some of these are:
  598.  
  599.         "K" for keyboard
  600.         "S" for the screen
  601.         "P" for the ZX Printer.
  602.  
  603. (You will be introduced to the others later.)
  604.  
  605. Note that K, S and P are all established channels. They required
  606. you to use commas (,) as separators in OPEN # statements. But with
  607. other channels you can use either commas or semi colons (;).
  608.  
  609. To create you own stream-channels you use the OPEN # statement. For
  610. example enter:
  611.  
  612.         10 OPEN #4,"S"
  613.  
  614. You will have opened stream 4 and linked it to channel S. Now enter
  615.  
  616.         20 PRINT #4;"This is a Spectrum computer"
  617.  
  618. Again, the line will appear on the screen.
  619.  
  620. (It is not advisable to OPEN to streams 0, 1 or 2 as the results are
  621. unpredictable.)
  622.  
  623.  
  624. Chapter 6
  625.  
  626. DATA AND THE MICRODRIVE
  627.  
  628.  
  629. Opening and naming a data file
  630.  
  631. When you store information in a cartridge you keep it in a files. You
  632. also give the file a name so that you can find it again later. The
  633. statement that opens and names a data files always takes the same
  634. form. For example try entering:
  635.  
  636.         OPEN #4;"m";1;"Numbers" -----------------\
  637.               |    \------\                      |
  638.         the stream number  "m";1 identifies the  "Numbers" is the file name.
  639.         can be any number  Microdrive you are    This can be any name you
  640.         from 0 to 15       using                 choose of up to ten
  641.                                                  characters in length.
  642.  
  643. This statement does two distinct jobs:
  644.  
  645. - it sets up a new channel: "m";1;"Numbers"
  646.  
  647. - it attaches this new channel to stream #4.
  648.  
  649. This will have taken about seven seconds, during which time the
  650. computer searches the cartridge for a file called "Numbers". Since
  651. there is no files "Numbers", it opens a file for writing. (However, if
  652. it had found a file "Numbers", it would have opened it for
  653. reading. And had it found a program "Numbers", it would have given the
  654. report 'Wrong file type'.)
  655.  
  656.  
  657. Entering data
  658.  
  659. Once you have opened a file you can enter data. Suppose that you want
  660. to store the numbers 1 to 10 with their squares. Enter and run this:
  661.  
  662.         10 FOR n=1 TO 10
  663.         20 PRINT #4,n'n*n
  664.         30 NEXT n
  665.  
  666. You might think that all the numbers have been stored away in the
  667. cartridge. But in fact the computer does not automatically transfer
  668. anything to the cartridge until a certain amount has built up, which
  669. it transfers all at once. This is called buffering. A Microdrive
  670. buffer is 512 bytes (or characters) long.
  671.  
  672. To store in the cartridge the data you have entered you must CLOSE the
  673. file. Until this is done you will be unable to read back from the
  674. file.
  675.  
  676.  
  677. Closing a file
  678.  
  679. Closing a file ensures that the file is safely stored in the
  680. cartridge. It also closes the channel (in this case "m";1;"Numbers")
  681. and leaves the stream (in this case #4) with no channels attached. To
  682. CLOSE a files you need only CLOSE the appropriate stream. So enter:
  683.  
  684.         CLOSE #4
  685.  
  686. The border will then flash to show that something is being stored in
  687. the cartridge.
  688.  
  689. (Note that, like the OPEN statement, the CLOSE statement is followed
  690. automatically by #.)
  691.  
  692. You cannot, by the way, CLOSE streams #0, #1, #2 or #3. If you try to
  693. do so, streams #0 and #1 will default to channel K; stream #2 will
  694. default to channel S; and stream #3 will default to channel P.
  695.  
  696.  
  697. Reading back from a file
  698.  
  699. To read back from the file "Numbers", run this
  700.  
  701.         10 OPEN #4;"m";1;"Numbers"
  702.         20 FOR b=1 TO 10
  703.         30 INPUT #4;m;n
  704.         40 PRINT "The Square of ";m;" is ";n
  705.         50 NEXT b              \     \  /
  706.         60 CLOSE #4        leave spaces here
  707.         RUN
  708.  
  709. (Note at this point that because the file "Numbers" already exists,
  710. the channel "m";1;"Numbers" is opened for input, and trying to output
  711. it would give an error.)
  712.  
  713. You can also use INKEY$ to read back from a file (it always gives the
  714. next character in the file). Try this program:
  715.  
  716.         10 OPEN #11;"m";1;"listing"
  717.         20 LIST #11
  718.         30 CLOSE #11
  719.         40 OPEN #12;"m";1;"listing"
  720.         50 PRINT INKEY$ #12;
  721.         60 GO TO 50
  722.  
  723. This will finish with the 'End of file' report.
  724.  
  725.  
  726. Notes on PRINT and INPUT
  727.  
  728. Because the PRINT and INPUT statements are designed mainly for use
  729. with the screen and keyboard, you must take care when using them with
  730. files.
  731.  
  732. separators
  733. The PRINT statement uses three forms of separator:
  734.  
  735. - the ; (semi colon) prints nothing.
  736.  
  737. - the , (comma) takes you to the start of the next half line,
  738.  
  739. - the ' (apostrophe) gives a new line (the ENTER code).
  740.  
  741. The INPUT statement always expects you to type ENTER after a number or
  742. a string. So, when you are printing to any file from which you expect
  743. to INPUT, you must either:
  744.  
  745. - print the items singly, e. g.
  746.  
  747.         10 PRINT #4;2
  748.         20 PRINT #4;3
  749.  
  750. or
  751.  
  752. - separate them with an apostrophe, e. g.
  753.  
  754.         10 PRINT #4;2'3
  755.  
  756. You must also take care when using separators in an INPUT
  757. statement. As you know, INPUT can print to the bottom half of the
  758. screen anything that you can put in a PRINT statement. But when you
  759. INPUT from a file, the file is only open for reading. So, if you
  760. include anything that would be printed when using the screen, you will
  761. get the error report 'Writing to a 'read' file'. This means that items
  762. in the INPUT statement should be separated with a semi colon, e. g.
  763.  
  764.         10 INPUT #4;a;b
  765.  
  766. Be careful also when you INPUT a string containing " (quotes). because
  767. the INPUT will think that the " is the end of the string. The way
  768. round this is to replace, for example:
  769.  
  770.         10 INPUT #4;a$
  771.  
  772. with
  773.  
  774.         10 INPUT #4; LINE a$
  775.  
  776. changing streams
  777. PRINT statements may also contain information for several streams at
  778. a time. The following program will print "one" on the screen; "two" to
  779. a Microdrive file called "digits" in Microdrive 1; "three" to station
  780. 1 on a network (see chapter 7); and "four" to next line on the screen.
  781.  
  782.         10 OPEN #4;"m";1;"digits"
  783.         20 OPEN #5;"n";1
  784.         30 PRINT "one";#4;"two";#5;"three";#2'"four"
  785.         40 CLOSE #4
  786.         50 CLOSE #5
  787.  
  788. setting colours
  789. After using a channel other than the screen, you may find that the
  790. PAPER and INK statements have no effect. To get round this, enter:
  791.  
  792.         PRINT ;
  793.  
  794. before setting PAPER and INK.
  795.  
  796. For more information about PRINT and INPUT see chapter 15 of the Basic
  797. programming manual.
  798.  
  799.  
  800. Reading the catalogue
  801.  
  802. As you establish files in a cartridge they are automatically
  803. catalogued. So, when you want to find out what file a cartridge
  804. contains, you need only insert the cartridge into a Microdrive and
  805. enter the CATalogue statement. For example, enter:
  806.  
  807.         CAT 1
  808.  
  809. The television screen will display:
  810.  
  811. - the cartridge name,
  812.  
  813. - the file names,
  814.  
  815. - the amount of memory left in the cartridge, (in kilobytes).
  816.  
  817. You can also send the output of CAT to a stream by entering:
  818.  
  819.         CAT #number; number
  820.              |         |
  821.         enter the      enter the
  822.         appropriate    Microdrive
  823.         stream         number
  824.         number here    here
  825.  
  826. This enables you to send the catalogue to a printer, or to a file, so
  827. that a program can use it.
  828.  
  829.  
  830. Protecting a file
  831.  
  832. If you do not want a file name to appear on the catalogue, you can
  833. protect it by giving it a name beginning with the character whose CODE
  834. is 0. Enter this:
  835.  
  836.         10 OPEN #4;"m";1;CHR$ 0+"Results"
  837.         20 FOR n=1 TO 15
  838.         30 PRINT #4;n,n*n
  839.         40 NEXT n
  840.         50 CLOSE #4
  841.  
  842. Now enter:
  843.  
  844.         CAT 1
  845.  
  846. The file name will not appear. So, whenever you create a protected
  847. file, remember to make a note of its name somewhere, in case you
  848. forget it later!
  849.  
  850.  
  851. Extending a file
  852.  
  853. Suppose that you want to extend the file "Numbers" to include the
  854. squares of the numbers 1 to 20 instead of only 1 to 10. You cannot
  855. reopen a file for writing, so you will have to:
  856.  
  857. - make a new version with a different name;
  858.  
  859. - transfer the old file to the new version;
  860.  
  861. - add the extra data;
  862.  
  863. - delete the old file.
  864.  
  865. Here is how to do it.
  866.  
  867. First RUN this program:
  868.  
  869.         10 OPEN #4;"m";1;"Numbers": REM for reading
  870.         20 OPEN #5;"m";1;"Numbers 1": REM for writing
  871.         30 FOR f=1 TO 10
  872.         40 INPUT #4;m;n
  873.         50 PRINT #5;m'n
  874.         60 NEXT f
  875.         70 FOR n=11 TO 20
  876.         80 PRINT #5;n'n*n
  877.         90 NEXT n
  878.        100 CLOSE #4: CLOSE #5
  879.  
  880. Now, to check that you have got two files, "Numbers" and "Numbers 1",
  881. enter:
  882.  
  883.         CAT 1
  884.  
  885. Next, to delete the old file, enter:
  886.  
  887.         ERASE "m";1;"Numbers"
  888.  
  889. To check that it has been deleted, enter:
  890.  
  891.         CAT 1
  892.  
  893. The file name "Numbers" will have disappeared from the catalogue, and
  894. your new file, "Numbers 1" now contains the numbers from 1 to 20.
  895.  
  896.  
  897. Chapter 7
  898.  
  899. THE LOCAL AREA NETWORK
  900.  
  901.  
  902. Setting up a network
  903.  
  904. The local area network, or net, enables you and your friends to play
  905. computer games together, and to send each other programs and
  906. data. This means that only one of you need to type in a program. A net
  907. is especially useful, too, if only one of you has a Microdrive.
  908.  
  909. Using the lead supplied with each Interface you can link up as few as
  910. two and as many as sixty-four Spectrum computers, as shown below.
  911.  
  912. Note, however, that you and your friends should not form a loop of
  913. computers: the computers at each end of the net should never be
  914. connected to each other. Each should be left with one net socket free.
  915.  
  916. NEVER SWITCH ON OR OFF A SPECTRUM WHICH IS ON A NET WHILE
  917. COMMUNICATION IS IN PROGRESS. You may, however, have a switched off
  918. Spectrum on the net; and you may also switch on or off Spectrums which
  919. are on a net provided that communication is not in progress.
  920.  
  921. When you have set up a net, each computer (or station) should be given
  922. a different identification number. So, first decide with your friends
  923. what number each station it to have, and then each of you should
  924. enter:
  925.  
  926.         FORMAT "n";number
  927.                     |
  928.                    enter here the station
  929.                    number you have chosen
  930.  
  931. Note, incidentally, that if there are only two computers on a net,
  932. both can use the same station number. And, since both computers, when
  933. switched on, become station 1 automatically, there is no need to use
  934. the FORMAT statement at all.
  935.  
  936.  
  937. Programs and the network
  938.  
  939. Let us suppose that you have a friend called Jack and that both of
  940. your computers are on a net. Your station number is, let us say, 1,
  941. and Jack's is 2.
  942.  
  943. Suppose that you want to send Jack this program:
  944.  
  945.         10 REM roots
  946.         20 FOR n=1 TO 10
  947.         30 PRINT n,SQR n
  948.         40 NEXT n
  949.  
  950. Enter the program, followed by:
  951.  
  952.         SAVE *"n";2
  953.  
  954. (Notice that the net does not use program names.)
  955.  
  956. Meanwhile, Jack should enter:
  957.  
  958.         FORMAT "n";2
  959.  
  960. followed by:
  961.  
  962.         LOAD *"n";1
  963.  
  964. Jack will now have a copy of the program. Notice, though, that while
  965. the computer is waiting to SAVE or LOAD a program over the net, the
  966. border of the screen goes black until the program is sent. You
  967. computer will not send until Jack's is ready, and Jack's will wait
  968. until something is sent. Try entering your SAVE line before Jack
  969. enters his LOAD line, and vice versa.
  970.  
  971. To verify that Jack now has a copy of your program, he should enter:
  972.  
  973.         VERIFY *"n";1
  974.  
  975. while you repeat the sending of the program by entering:
  976.  
  977.         SAVE *"n";2
  978.  
  979. SAVE is, in fact, the only statement that sends programs over the
  980. net. The LOAD, VERIFY and MERGE statements are all ways of receiving
  981. programs.
  982.  
  983. The net game in Appendix 1 is a good example of how to use programs
  984. with a network.
  985.  
  986.  
  987. Data and the network
  988.  
  989. Suppose that you want to send Jack some data. The statement OPEN
  990. #4;"n";2 opens a channel to station 2 on the net ("n"), and attaches
  991. stream #4, to it, so that when you output along stream #4, your
  992. message will be put on the net with a note saying that it comes from
  993. you.
  994.  
  995. (Conversely, were you to enter INPUT #4;"n";2 your computer would wait
  996. for information addressed to you from Jack.)
  997.  
  998. Now enter this programs:
  999.  
  1000.         10 OPEN #4;"n";2: REM for output
  1001.         20 INPUT a$: PRINT #4;a$
  1002.         30 CLOSE #4
  1003.         40 OPEN #4;"n";2: REM for input
  1004.         50 INPUT #4;b$: PRINT b$
  1005.         60 CLOSE #4
  1006.         70 GO TO 10
  1007.  
  1008. Then enter:
  1009.  
  1010.          SAVE *"n";2
  1011.  
  1012. Now ask Jack to enter:
  1013.  
  1014.         FORMAT "n";2
  1015.  
  1016. Then:
  1017.  
  1018.         LOAD *"n";1
  1019.  
  1020. You should now run your program, and Jack should edit lines 10 and 40
  1021. of the program to make them refer to station 1 not station 2. He
  1022. should then enter:
  1023.  
  1024.         GO TO 40
  1025.  
  1026. You are now ready to start a conversation. But before you do so there
  1027. are three things you should know:
  1028.  
  1029. - Your output along stream #4 is buffered: that is, it is not
  1030.   automatically put on the net until a certain amount of output has
  1031.   accumulated. So whenever you finish outputting you should CLOSE the
  1032.   stream. This will send the buffer even if it is not full. (The
  1033.   buffers are 255 bytes, or characters, long.)
  1034.  
  1035. - Your output is marked as coming specifically from you, so that if
  1036.   Jack is inputting or waiting for output from a different net
  1037.   channel, your message will be ignored. If your message has been
  1038.   ignored your screen will not display the OK message, and the border
  1039.   of the screen will go black, until Jack asks to receive the message.
  1040.  
  1041. - Though the INPUT statement simply waits for something to be sent,
  1042.   the INKEY$ statement can be used to read the net. It will return
  1043.   with the first byte of anything that either has been sent, or is
  1044.   waiting to be sent. (Otherwise it will return the empty string.)
  1045.   This is known as polling. (INKEY$, in fact, works the same way with
  1046.   the net as it does with the keyboard.)
  1047.  
  1048. The program below will print anything being sent to it by station 1:
  1049.  
  1050.         10 OPEN #8;"n";1
  1051.         20 PRINT INKEY$ #8;
  1052.         30 GO TO 20
  1053.  
  1054. (For more on INKEY$ see chapter 18 of the BASIC programming manual.)
  1055.  
  1056.  
  1057. Broadcasting
  1058.  
  1059. There is also a special net channel called broadcast whose channel
  1060. specifier is "n";0. When you input from this channel you will pick up
  1061. any message that is being broadcast. And when you output, you message
  1062. can be read by anyone who is inputting from channel "n";0.
  1063.  
  1064. This could, for example, be very useful at school if every pupil in a
  1065. class has a Spectrum computer, but only the teacher has a Microdrive.
  1066.  
  1067. Suppose the teacher wished to broadcast a program. First, the pupils
  1068. should enter:
  1069.  
  1070.         LOAD *"n";0
  1071.  
  1072. This will leave the pupils 'waiting' to receive the program. The
  1073. teacher should then save the program by entering:
  1074.  
  1075.         SAVE *"n";0
  1076.  
  1077. As you may have guessed, broadcast (unlike private messages) are sent
  1078. at once, and do not wait for other computers to be ready to receive
  1079. them.
  1080.  
  1081. Note, by the way, that when you send a broadcast, the computer does
  1082. not let you know if anyone has received it.
  1083.  
  1084. Note also that INKEY$ will not poll the broadcast channel. Like INPUT,
  1085. it will simply wait for something to be sent.
  1086.  
  1087.  
  1088. Chapter 8
  1089.  
  1090. USING THE RS232 INTERFACE
  1091.  
  1092.  
  1093. Connecting peripherals tot he RS232 Interface
  1094.  
  1095. As you know, the Spectrum character set comprises both single symbols
  1096. (letters, digits, etc.) and compound tokens (keywords, function names,
  1097. etc.). All these characters can be sent and received by the RS232
  1098. Interface to and from any compatible serial device; for example, a
  1099. printer, a modem or another RS232 Interface connected to a different
  1100. kind of computer.
  1101.  
  1102. To connect any of these peripherals to the RS232, you should use a
  1103. lead with a 9-way D-plug on one end and an appropriate plug for you
  1104. peripheral on the other. You should insert the D-plug into the back of
  1105. the RS232, as shown below. (For wiring details, see Appendix 4.)
  1106.  
  1107. Next, before you can use the RS232 you will need to adjust some of the
  1108. settings on the peripheral. These may include:
  1109.  
  1110. - auto line feed, which should normally be switched to off. (The
  1111.   Spectrum outputs a carriage return and a line feed on a "t" channel
  1112.   but a carriage return only on a "b" channel. These t and b channels
  1113.   are explained below.)
  1114.  
  1115. - parity on/off, which should be set off.
  1116.  
  1117. - the number of bits, since the Spectrum puts out eight bits.
  1118.  
  1119. - the number of stop bits, since the Spectrum puts out one stop bit.
  1120.  
  1121. - the baud rate (i. e. the number of bits per second). The Spectrum
  1122.   can operate at all standard baud rates, i. e.:
  1123.   50, 110, 300, 600, 1200, 2400, 4800, 9600 and 19,200.
  1124.  
  1125.   You should set your peripheral to use the highest baud rate of which
  1126.   it is capable. (You will see later how to set the Spectrum to use
  1127.   the same baud rate.)
  1128.  
  1129. For an explanation of how to make these adjustments, consult the
  1130. instruction book supplied with your peripheral.
  1131.  
  1132.  
  1133. T and b channel
  1134.  
  1135. The RS232 uses two different channels: the t channel and the b
  1136. channel.
  1137.  
  1138.  
  1139. The t channel
  1140.  
  1141. The t (or text) channel is normally used to send listings. Channel t
  1142. has the following effect on the character set:
  1143.  
  1144. character
  1145. 0-31            (control codes) are not sent, except 13 (carriage
  1146.                 return) which is sent as 13 followed by 10 (carriage
  1147.                 return and line feed).
  1148.  
  1149. 32-127          (the ASCII code) are sent as normal.
  1150.  
  1151. 128-164         (the graphics characters) are not sent. The message ?
  1152.                 (code 63) is sent instead.
  1153.  
  1154. 16-255          (the tokens) are expanded into ASCII codes 32-127
  1155.  
  1156. On INPUT and INKEY$ the t channel expects 7 bits characters, so it
  1157. ignores the 8th bit if there is one.
  1158.  
  1159. To use the t channel, first you must tell the computer which baud rate
  1160. to use. So enter:
  1161.  
  1162.         10 FORMAT "t";baud rate
  1163.                         |
  1164.                 enter here the baud rate
  1165.                 you have set your
  1166.                 peripheral to use
  1167.  
  1168. Now to OPEN a stream to it, enter:
  1169.  
  1170.         20 OPEN #3;"t"
  1171.         30 LLIST
  1172.  
  1173. The border of the screen will flash and the listing will be sent to
  1174. the peripheral. (Notice that LLIST is shorthand for LIST #3.) Now
  1175. enter:
  1176.  
  1177.         LPRINT "This is a short message."
  1178.  
  1179. If your ZX Interface is connected to a terminal or an RS232 device
  1180. capable of sending, then you can INPUT from the terminal or
  1181. device. Enter this:
  1182.  
  1183.         10 FORMAT "t";baud rate
  1184.         20 OPEN #4;"t"   \------ enter here the baud
  1185.         30 PRINT INKEY$ #4;      rate you have set
  1186.         40 GO TO 30              your peripheral to use
  1187.  
  1188. Now, whatever you type on the terminal or device will appear on your
  1189. screen.
  1190.  
  1191.  
  1192. The b channel
  1193.  
  1194. The b (or binary) channel sends the full 8 bit codes used by the
  1195. Spectrum, and allows you to send control codes to printers etc.
  1196.  
  1197. With INPUT and INKEY$ the b channel expects 8 bit characters.
  1198.  
  1199. SAVE and LOAD will only work with the b channel.
  1200.  
  1201. If you are using modems to connect your computer with another Spectrum
  1202. over a 'phone line; or if you are storing your programs on a different
  1203. kind of computer which also has an RS232 Interface, you may well want
  1204. to SAVE and LOAD over the RS232 Interface. To do this, enter:
  1205.  
  1206.         FORMAT "b";baud rate
  1207.                         |
  1208.                 enter here the baud rate you
  1209.                 have set your peripheral to use
  1210.  
  1211. Now, for example, enter:
  1212.  
  1213.         10 REM figures
  1214.         20 FOR n=1 TO 10
  1215.         30 PRINT n,n*RND
  1216.         40 NEXT n
  1217.  
  1218. followed by:
  1219.  
  1220.         SAVE *"b"
  1221.  
  1222. If this program is being send via modem, someone at the other end
  1223. should enter:
  1224.  
  1225.         LOAD *"b"
  1226.  
  1227. The usual extensions are also possible, such as:
  1228.  
  1229.         SAVE *"b";SCREEN$
  1230.  
  1231. and:
  1232.  
  1233.         SAVE *"b";LINE number
  1234.  
  1235.  
  1236. Sending control codes
  1237.  
  1238. Many printers allow you to send instructions for such operations as
  1239. double width printing. To send these you should use the b
  1240. channel. However, with the b channel, the carriage return does not
  1241. include a line feed. So you will have either to change the settings on
  1242. your printer, or print the line feed code: 10.
  1243.  
  1244. For example, suppose that the control code for double width printing
  1245. is 14. Enter:
  1246.  
  1247.         10 OPEN #4;"b"
  1248.         20 PRINT #4;"Normal width"
  1249.         30 PRINT #4;CHR$ 14;"Double width"
  1250.         40 CLOSE #4
  1251.  
  1252. (For the correct control codes to use, refer to your printer's
  1253. instruction book.)
  1254.  
  1255. You can have both b and t channels at once. Try entering this:
  1256.  
  1257.         10 OPEN #5;"b"
  1258.         20 OPEN #6;"t"
  1259.         30 PRINT #5;CHR$ 14;
  1260.         40 LIST #6
  1261.         50 CLOSE #5: CLOSE #6
  1262.  
  1263. This would give you a double width listing.
  1264.  
  1265.  
  1266. Chapter 9
  1267.  
  1268. THE MOVE STATEMENT
  1269.  
  1270.  
  1271. So far, you have only been able to move data from a program to a
  1272. channel or vice versa. The MOVE statement, however, enables you to
  1273. move data from one channel to another. For example, to move data from
  1274. the keyboard to the screen, enter:
  1275.  
  1276.         10 MOVE #1 TO #2
  1277.  
  1278. then:
  1279.  
  1280.         RUN
  1281.  
  1282. Anything you type on the keyboard will now appear on the
  1283. screen. However, you will discover that when you press BREAK this only
  1284. prints a space on the screen. To escape from this trap, press ENTER
  1285. until the print position reaches the bottom of the screen. The, when
  1286. the computer asks 'scroll?' you should press BREAK. (You should, by
  1287. the way, avoid moving data from the keyboard to any other stream since
  1288. you may be unable to BREAK out of such a mode.)
  1289.  
  1290. Using the MOVE statement you can also examine files stored in
  1291. cartridges. For example, set up the file "Numbers" and then, to
  1292. examine its contents, enter:
  1293.  
  1294.         10 MOVE "m";1;"Numbers" TO #2
  1295.  
  1296. (Note that you need not OPEN or CLOSE the file yourself. MOVE does
  1297. this.)
  1298.  
  1299. Similarly, to make a copy of the file "Numbers" enter:
  1300.  
  1301.         10 MOVE "m";1;"Numbers" TO "m";1;"Numbers 2"
  1302.  
  1303. Here, MOVE opens a stream for reading from the existing file
  1304. ("Numbers") and another for writing to the new file ("Numbers
  1305. 2"). Next, it reads the data in "Numbers" and writes it out in
  1306. "Numbers 2". Then it closes both streams.
  1307.  
  1308. MOVE will work with stream numbers (such as #4), and with channel
  1309. specifiers (such as "m";1;"Numbers"). Note, however, that the
  1310. established streams, #1 to #3, may not be specified by the channel
  1311. specifiers K, S or P.
  1312.  
  1313. If you have a second Microdrive, you can use the MOVE statement to
  1314. make back-up copies of data in another cartridge. Enter:
  1315.  
  1316.         10 MOVE "m";1;"Numbers" TO "m";2;"Numbers 2"
  1317.  
  1318. (Note that MOVE only works with data files. If you want a back-up copy
  1319. of a program, you must LOAD the program, and then SAVE it.)
  1320.  
  1321. It is sensible to make back-up copies of any data or programs you want
  1322. to keep.
  1323.  
  1324. The MOVE statement can also send files to a printer. So if you have a
  1325. ZX Printer, enter:
  1326.  
  1327.         10 MOVE "m";1;"Numbers" TO #3
  1328.  
  1329.  
  1330. The Printer Server program
  1331.  
  1332. This program allows one Spectrum on a net to control an RS232
  1333. printer. The printer can then be used by all other computers on the
  1334. net. This is useful, for example, if a group of people using Spectrums
  1335. have only one high quality printer among them which they wish to
  1336. share. The program also shows a powerful use of the MOVE statement.
  1337.  
  1338. The Printer Server computer must always be station 64, and must always
  1339. make contact with station 62 (which is a contact establishing
  1340. station). So the sender temporarily uses station 62, and sends it his
  1341. real station number from which it then moves a files to the t
  1342. channel. To set up a Printer Server station use this program:
  1343.  
  1344.         10 FORMAT "n";64
  1345.         20 OPEN #4;"n";62: INPUT #4;a$: CLOSE #4
  1346.         30 MOVE "n"; CODE a$ TO "t"
  1347.         40 OPEN #4;"b": PRINT #4;CHR$ 12: CLOSE #4: RUN
  1348.  
  1349. (Line 40 sends a form feed.)
  1350.  
  1351. The program below is the one send by the sender. First, the sender's
  1352. station is temporarily set to station 62. Then, the sender's real
  1353. station number is sent. Next the sender's station sets itself back to
  1354. its real number. Last, line 60 sends whatever data is to be printed
  1355. (in this case, the listing).
  1356.  
  1357.         10 LET station=number
  1358.         20 FORMAT "n";62 \-- enter here the sender's real station number
  1359.         30 OPEN #4;"n";64: PRINT #4;CHR$ station: CLOSE #4
  1360.         40 FORMAT "n";station
  1361.         50 OPEN #4;"n";64
  1362.         60 LIST #4
  1363.         70 CLOSE #4
  1364.  
  1365.  
  1366. Appendix 1
  1367.  
  1368. THE NET GAME
  1369.  
  1370.  
  1371. There is a copy of this game on the demonstration cartridge supplied
  1372. with the Microdrive. Its file name is "net game". The program gives a
  1373. good example of how the net can be used. Parts of it might usefully be
  1374. included in programs of your own.
  1375.  
  1376.  
  1377. The game
  1378.  
  1379. To play this game, you and your opponent must each think of a number
  1380. between 1 and 100. The winner of the game is the one who guesses his
  1381. opponent's number first. At each guess you make, your computer will
  1382. tell you how close you are getting.
  1383.  
  1384.  
  1385. The program
  1386.  
  1387. The subroutine at line 500 decides who is user 1 and who is user
  1388. 2. This is so that, when you exchange guesses, one of you uses the
  1389. subroutine at line 1100, and the other uses the subroutine at line
  1390. 1200 and thus user 1 sends first and user 2 receives first.
  1391.  
  1392. Your computer decides who is user 1 by sending your opponent's
  1393. computer the message "1", and then listening. If it receives back a
  1394. "1", this means that opponent's computer was switched on after
  1395. yours. Your computer therefore sends a "2" to your opponent's
  1396. computer, and makes itself user 1. (If, on the other hand, your
  1397. computer receives back a "2", this means that your opponent sent the
  1398. "1". Your computer will therefore make itself user 2.)
  1399.  
  1400. If both computers start at the same time they collide and it will be
  1401. necessary to BREAK and start again.
  1402.  
  1403. The body of the program is involved with exchanging names, inputting
  1404. the secret number (which is not sent) and then comparing
  1405. guesses. First guesses are sent, and then the replies.
  1406.  
  1407. Lines 190 onwards detect a win, signal it appropriately, and then
  1408. offer another game.
  1409.  
  1410.   10 GO SUB 500
  1411.   20 PRINT ;: BORDER 1: PAPER 1: INK 7: CLS
  1412.   30 PRINT " Number guessing game"''"First enter your secret number,
  1413.      then guess your opponent's"
  1414.   40 INPUT "What is your name?";a$
  1415.   50 PRINT ''"Hello ";a$
  1416.   60 GO SUB 1000+100*user
  1417.   70 PRINT "You are playing ";b$
  1418.   75 PRINT 'a$,b$
  1419.   80 INPUT "Think of a number (1 to 100)";a
  1420.   90 IF a<1 OR a>100 OR a<>INT a THEN GO TO 80
  1421.  130 INPUT "Make a guess ";b
  1422.  140 LET a$=STR$ b: GO SUB 1000+100*user
  1423.  150 LET c=ABS(a-VAL b$)
  1424.  160 IF c=0 THEN LET a$="Right": GO TO 170
  1425.  161 IF c<4 THEN LET a$="Very very close": GO TO 170
  1426.  162 IF c<10 THEN LET a$="Very close": GO TO 170
  1427.  163 IF c<20 THEN LET a$="close" : GO TO 170
  1428.  164 IF c<40 THEN LET a$="fairly close": GO TO 170
  1429.  165 IF c<60 THEN LET a$="not very close": GO TO 170
  1430.  166 LET a$="nowhere near"
  1431.  170 GO SUB 1000+100*user
  1432.  180 PRINT b$,a$
  1433.  190 IF c=0 OR b$="Right" THEN GO TO 210
  1434.  200 GO TO 130
  1435.  210 IF b$="Right" THEN PRINT FLASH 1;"Victory": FOR n=1 TO 7:
  1436.      BORDER n: BEEP .1,n: BEEP .1,n+16: NEXT n: GO TO 230
  1437.  220 PRINT "Defeat": FOR n=7 TO 0 STEP -1: BORDER n: BEEP .2,n: NEXT n
  1438.  230 BORDER 1: INPUT "Another game? (y/n)";a$
  1439.  240 IF a$="y" THEN RUN 20
  1440.  499 STOP
  1441.  500 OPEN #4;"n";0
  1442.  510 PRINT #4;"1"
  1443.  520 CLOSE #4
  1444.  530 OPEN #4;"n";0
  1445.  540 INPUT #4;a$
  1446.  545 CLOSE #4
  1447.  550 LET a=4: IF a$="1" THEN OPEN #a;"n";0: PAUSE 5: PRINT #4;"2":
  1448.      LET user=1
  1449.  560 IF a$="2" THEN LET user=2
  1450.  570 CLOSE #4
  1451.  580 FORMAT "n";user: RETURN
  1452. 1100 OPEN #4;"n";3-user
  1453. 1110 PRINT #4;a$
  1454. 1120 CLOSE #4
  1455. 1130 OPEN #4;"n";3-user
  1456. 1140 INPUT #4;b$
  1457. 1150 CLOSE #4
  1458. 1160 RETURN
  1459. 1200 OPEN #4;"n";3-user
  1460. 1210 INPUT #4;b$
  1461. 1220 CLOSE #4
  1462. 1230 OPEN #4;"n"3-user
  1463. 1240 PRINT #4;a$
  1464. 1250 CLOSE #4
  1465. 1260 RETURN
  1466.  
  1467.  
  1468. Appendix 2
  1469.  
  1470. SYSTEM VARIABLES
  1471.  
  1472.  
  1473. In addition to the system variables given in Chapter 25 of the
  1474. Spectrum BASIC programming manual, the Microdrive, local area network
  1475. and RS232 software use the system variables below.
  1476.  
  1477. Notes   Address Name    Contents
  1478. X1      23734   FLAGS3  Flags
  1479. X2      23735   VECTOR  Address used to extend the BASIC interpreter
  1480. X10     23737   SBRT    ROM paging subroutine
  1481. 2       23747   BAUD    Two byte number determining the baud rate
  1482.                         calculated as follows:
  1483.                         BAUD=(3500000 / (26 * baud rate)) - 2
  1484. 1       23749   NTSTAT  Own network station number
  1485. 1       23750   IOBORD  Border colour used during I/O. You can poke
  1486.                         any colour you want.
  1487. N2      23751   SER_FL  2 byte workspace used by RS232
  1488. N2      23753   SECTOR  2 byte workspace used by Microdrive
  1489. N2      23755   CHADD_  Temporary store for CH_ADD
  1490. 1       23757   NTRESP  Store for network response code
  1491. 1       23758   NTDEST  Beginning of network buffer contains
  1492.                         destination station number 0-64
  1493. 1       23759   NTSRCE  Source station number
  1494. X2      23760   NTNUMB  Network block number 0-65535
  1495. N1      23762   NTTYPE  Header type code
  1496. X1      23763   NTLEN   Data block length 0-255
  1497. N1      23764   NTDCS   Data block checksum
  1498. N1      23765   NTHCS   Header block checksum
  1499. N2      23766   D_STR1  Start of 8 byte file specifier
  1500.                         2 byte drive number 1-8
  1501. N1      23768   S_STR1  Stream number 1-15
  1502. N1      23769   L_STR1  Device type... "m", "n", "t" or "b"
  1503. N2      23770   N_STR1  Length of file name
  1504. N2      23772   D_STR2  Second 8 byte file specifier
  1505.                         used by MOVE and LOAD commands
  1506. N1      23782   HD_00   Start of workspace for SAVE, LOAD, VERIFY and
  1507.                         MERGE data type code
  1508. N2      23783   HD_0B   Length of data 0-66535
  1509. N2      23785   HD_0D   Start of data 0-65535
  1510. N2      23787   HD_0F   Program length 0-66535
  1511. N2      23789   HD_11   Line number
  1512. 1       23791   COPIES  Number of copies made by SAVE
  1513.         23792   Start of Microdrive MAPs or CHANS
  1514.  
  1515. WARNINGS
  1516.  
  1517. 1. Opening a stream to the Microdrive or net requires a certain amount
  1518.    of free memory with which to create a channel. A Microdrive channel
  1519.    is 595 bytes, and a net channel is 276 bytes. These channels will
  1520.    be created either by OPEN #, MOVE or by SAVE / LOAD / VERIFY /
  1521.    MERGE. This means that an existing program with insufficient room
  1522.    below RAMTOP will give the report 'Out of memory' to any of these
  1523.    operations.
  1524.  
  1525. 2. Another effect of the creation of these buffers is to move machine
  1526.    code stored in a REM statement. This may create problems. So always
  1527.    put machine code programs above RAMTOP.
  1528.  
  1529. 3. It is inadvisable to BREAK during a Microdrive write operation (one
  1530.    during which the border is flashing), since you may end up with an
  1531.    unclosed file. ERASE will remove unclosed files, but will take
  1532.    about thirty seconds to do so, as the computer checks the cartridge
  1533.    several times to make sure that the file has no end.
  1534.  
  1535.  
  1536. Appendix 3
  1537.  
  1538. MICRODRIVE CHANNEL
  1539.  
  1540.  
  1541. Every time a file is opened an area called a CHANNEL is created in the
  1542. area designated CHANS in the BASIC programming manual. This area is
  1543. usually addressed by the IX register in the software. The channel has
  1544. a length of 596 bytes, and contains the 512 byte buffer.
  1545.  
  1546. The contents of the channel are as follows:
  1547.  
  1548. 0               Address 8
  1549. 2               Address 8
  1550. 4               'M'
  1551. 5               Address of output subroutine in ROM
  1552. 7               Address of input routine in ROM
  1553. 9               Address 595
  1554. 11      CHBYTE  Current byte counter indicates the next byte to be
  1555.                 added or removed from the data area in the range 0-512
  1556.                 inclusive
  1557. 13      CHREC   Record number. Indicates the position of the record in
  1558.                 a file range 0-255
  1559. 14      CHNAME  10 byte filename with trailing spaces
  1560. 24      CHFLAG  Flag byte       bit 0    set...open for write
  1561.                                          clear open for read
  1562.                                 bits 1-7 unused
  1563. 25      CHDRIV  Drive number 0-7
  1564. 26      CHMAP   Address of the MAP for this Microdrive
  1565. 28      CHMAP   12 bytes of header preamble... marks the start of the
  1566.                 header workspace
  1567. 40      HDFLAG  Flag byte       bit 0    set
  1568.                                 bits 1-7 unused
  1569. 41      HDNUMB  Sector number in range 0-255
  1570. 42              Unused
  1571. 44      HDNAME  Cartridge name and trailing spaces
  1572. 54      HDCHK   Header checksum
  1573. 55              12 Bytes of data block preamble... marks the start of
  1574.                 the data workspace
  1575. 67      RECFLG  Flag byte bit 0 = 0
  1576.                           bit 2 = not a PRINT file
  1577.                           bit 3-7 unused
  1578. 68      RECNUM  Number of this record in the range 0-255
  1579. 69      RECLEN  Number of bytes of data in this record 0-512
  1580. 71      RECNAM  Filename with trailing spaces
  1581. 81      DESCHK  Checksum of the preceding 14 bytes
  1582. 82      CHDATA  512 bytes of data
  1583. 594     DCHK    Checksum of the preceding 512 bytes
  1584.  
  1585.  
  1586. MAP
  1587.  
  1588. For every Microdrive containing an opened file there is an area called
  1589. MAP created in the area called "Microdrive maps" in the BASIC
  1590. Programming manual. The MAP contains 32 bytes. Each bit corresponds to
  1591. a sector on the corresponding Microdrive. If that sector contains data
  1592. or if it is unusable then the bit is set. The bits are numbered as
  1593. follows: bit 0 byte 0 = sector 0, bit 1 byte 0 = sector 1, bit 0 byte
  1594. 1 = sector 8, and so on.
  1595.  
  1596.  
  1597. NETWORK CHANNEL
  1598.  
  1599. When a stream is opened to the network, a channel is created in the
  1600. area designated CHANS in the BASIC Programming manual. This area is
  1601. usually addressed by the IX register in the software. The channel has
  1602. a length of 276 bytes, and contains the 255 bytes buffer.
  1603.  
  1604. The contents of the channel are described as follows:
  1605.  
  1606. 0               Address 8
  1607. 2               Address 8
  1608. 4               "N"
  1609. 5               Address of output subroutine in ROM
  1610. 7               Address of input subroutine in ROM
  1611. 9               Address 276
  1612. 11      NCIRIS  The destination station number
  1613. 12      NCSELF  The Spectrum's station number
  1614. 13      NCNUMB  The block number
  1615. 15      NCTYPE  The packet type code... 0 data, 1 EOF
  1616. 16      NCOBL   Number of bytes in the data block
  1617. 17      NCDCS   The data checksum
  1618. 18      NCHCS   The header checksum
  1619. 19      NCCUR   The position of the last character taken from the
  1620.                 buffer
  1621. 20      NCIBL   The number of bytes in the input buffer
  1622. 21      NCB     A 255 byte data buffer
  1623.  
  1624.  
  1625. Appendix 4
  1626.  
  1627. RS232 CONNECTIONS
  1628.  
  1629.  
  1630. /----------------------\
  1631. \ 5 o   o   o   o   o 1/
  1632.  \  9 o   o   o   o 6 /
  1633.   \------------------/
  1634.  
  1635. The RS232 socket is wired as follows:
  1636.  
  1637. 1. No connection
  1638. 2. TX data (input)
  1639. 3. RX data (output)
  1640. 4. DTR (input) this should be high when ready
  1641. 5. CTS (output) this should be high when ready
  1642. 6. N.c.
  1643. 7. Ground (pull down)
  1644. 8. N.c.
  1645. 9. +9V (pull up)
  1646.  
  1647. An RS232 cable is available from Sinclair Research, which connects
  1648. the 9 way D-socket to a 25 way D-plug (25 way D-sockets are common on
  1649. RS232 peripherals). For details of how to obtain this cable, see the
  1650. software and peripherals catalogue included with the ZX Interface
  1651. 1. This cable is wired as follows:
  1652.  
  1653.  2. TX data
  1654.  3. RX data
  1655.  5. CTS
  1656.  6. +9V (normally DSR)
  1657.  7. Ground
  1658. 20. DTR
  1659.  
  1660.  
  1661. Appendix 5
  1662.  
  1663. REPORTS
  1664.  
  1665.  
  1666. Now that you have attached a ZX Interface 1 to your computer, your
  1667. programs may produce reports which are not described in Appendix B of
  1668. the BASIC programming manual. Such reports will be followed by the
  1669. line number and the statement number at which the program stopped.
  1670.  
  1671. These new reports are explained (in alphabetical order) below.
  1672.  
  1673.  
  1674. Code error
  1675.  
  1676. You have tried to LOAD a code block that is larger than the
  1677. destination area specified by your LOAD statement.
  1678.  
  1679.  
  1680. Drive 'write' protected
  1681.  
  1682. You have tried to write data to a Microdrive containing a protected
  1683. cartridge (i. e. one with the plastic tab on the side removed).
  1684.  
  1685.  
  1686. File not found
  1687.  
  1688. This means that either you have tried to LOAD from a file which does
  1689. not exist, or part of the file cannot be found. (This would either be
  1690. because the file has not been closed, or because the file has been
  1691. damaged by the power being switched on or off while the cartridge was
  1692. in a Microdrive.)
  1693.  
  1694.  
  1695. Invalid device expression
  1696.  
  1697. A device has been specified other than s, p, k, m, n, t or b. The same
  1698. report can be produced if a semi-colon, rather than a comma, is used
  1699. with one of the channels s, p or k.
  1700.  
  1701.  
  1702. Invalid drive number
  1703.  
  1704. A Microdrive number has been specified outside the range 1 to 8.
  1705.  
  1706.  
  1707. Invalid name
  1708.  
  1709. A file name has been specified as an empty string or a string with
  1710. more than ten characters.
  1711.  
  1712.  
  1713. Invalid station number
  1714.  
  1715. A network station has been specified outside the range 0 to 6 (or
  1716. outside the range 1 to 64 for FORMAT statements).
  1717.  
  1718.  
  1719. Invalid stream number
  1720.  
  1721. A stream has been specified outside the range 0 to 15.
  1722.  
  1723.  
  1724. Merge error
  1725.  
  1726. You have tried to MERGE data or code. You can only MERGE
  1727. programs. This report will also appear if you have tried to MERGE a
  1728. program saved by the SAVE... LINE... statement.
  1729.  
  1730.  
  1731. Microdrive full
  1732.  
  1733. You have tried to write data to a cartridge containing no free
  1734. space. You should therefore run your program or command again, with a
  1735. cartridge that does contain free space. This can be done by erasing
  1736. old files from the present cartridge. A file opened for writing on
  1737. the full cartridge cannot be closed. It should be erased. This will,
  1738. however, take about thirty seconds because the computer checks the
  1739. cartridge several times to make sure that the file has no end.
  1740.  
  1741.  
  1742. Microdrive not present
  1743.  
  1744. You have either tried to use a Microdrive which is not attached to
  1745. your computer, or a Microdrive which does not contain a cartridge, or
  1746. a Microdrive containing an unformatted cartridge.
  1747.  
  1748.  
  1749. Missing baud rate
  1750.  
  1751. The baud rate has not been specified.
  1752.  
  1753.  
  1754. Missing drive number
  1755.  
  1756. The Microdrive number has not been specified.
  1757.  
  1758.  
  1759. Missing name
  1760.  
  1761. The file name has not been specified.
  1762.  
  1763.  
  1764. Missing station number
  1765.  
  1766. The network station number has not been specified.
  1767.  
  1768.  
  1769. Program finished
  1770.  
  1771. You have tried to execute a line beyond any existing line. This report
  1772. will appear if a GO TO instruction is followed by a number beyond any
  1773. existing line. It will also appear if RUN is typed without a program.
  1774.  
  1775.  
  1776. Read a 'write' file
  1777.  
  1778. You have tried to input from a file which does not yet exist, or
  1779. which has already been opened for input.
  1780.  
  1781.  
  1782. Stream already open
  1783.  
  1784. You have tried to OPEN to a stream which has already been opened to a
  1785. new channel (m, n, t or b). The stream can only be opened if it is
  1786. first closed.
  1787.  
  1788.  
  1789. Verification has failed
  1790.  
  1791. A saved file does not agree with the program, data or code currently
  1792. in the computer.
  1793.  
  1794.  
  1795. Writing to a 'read' file
  1796.  
  1797. You have tried to output data to an existing file. The existing file
  1798. should be erased if it is not needed. Otherwise, a new file should be
  1799. used.
  1800.  
  1801.  
  1802. Wrong file type
  1803.  
  1804. You have tried to INPUT or MOVE a saved file or to LOAD, VERIFY or
  1805. MERGE a PRINT type of file, or to LOAD a CODE or DATA files as a
  1806. program (or vice versa).
  1807.  
  1808. If you are using INPUT then you should be using LOAD. If you are using
  1809. LOAD then either you should use the CODE to DATA options or you should
  1810. use INPUT.
  1811.  
  1812.  
  1813. Appendix 6
  1814.  
  1815. THE EXTENDED BASIC
  1816.  
  1817.  
  1818. The ZX Interface 1 extends the BASIC already in the Spectrum. The
  1819. extensions and additions are summarised below.
  1820.  
  1821.  
  1822. Streams
  1823.  
  1824. Streams are specified as #n where n is a number in the range
  1825. 1-15. Streams 1, 2 and 3 are usually used by BASIC. The # character is
  1826. part of the keyword for the OPEN # and CLOSE # statements.
  1827.  
  1828.  
  1829. Channels
  1830.  
  1831. There are seven types of channel in the extended BASIC; the keyboard
  1832. (k), the screen (s), the ZX Printer (p), the text RS232 Interface (t),
  1833. the binary RS232 Interface (b), the network (n) and the Microdrive
  1834. (m).
  1835.  
  1836. Each channel type is specified by its letter which may be upper case
  1837. or lower case. The network and the Microdrive require additional
  1838. information to specify the channel completely.
  1839.  
  1840. A network channel requires a station number, so a network channel is
  1841. specified as "n";x where x is a station number in the range 0-64.
  1842.  
  1843. A Microdrive channel requires a Microdrive number and a file name, so
  1844. a Microdrive channel is specified as "m";y;"name" where y is the
  1845. Microdrive number in the range 1-8 and "name" is a string of between 1
  1846. and 10 characters.
  1847.  
  1848. Statements
  1849.  
  1850. CAT y                   Gives a list of all the files in the cartridge
  1851.                         in Microdrive y. The list is presented in
  1852.                         alphabetical order and is preceded by the name
  1853.                         of the cartridge and followed by the remaining
  1854.                         capacity in kilobytes.
  1855.  
  1856.  
  1857. CAT #z;y                Sends the catalogue of the cartridge in
  1858.                         Microdrive y, as described above, to stream z.
  1859.  
  1860. CLOSE #stream           Unlinks any channel from the specified
  1861.                         stream. If there is any buffered data then
  1862.                         this is either transmitted (on the network) or
  1863.                         recorded (on the Microdrive).
  1864.  
  1865. ERASE "m";y;"name"      Erase the file with the specified name from
  1866.                         the cartridge in Microdrive y.
  1867.  
  1868. FORMAT "m";y;"name"     Prepare a blank Microdrive cartridge in
  1869.                         Microdrive y for use by BASIC. The name "name"
  1870.                         is given to the cartridge and this will appear
  1871.                         in catalogues.
  1872.  
  1873. FORMAT "n";x            Sets the network station to x.
  1874.  
  1875. FORMAT "t";x \          Set the baud rate for the RS 232 Interface to
  1876. FORMAT "b";x /          x (x should be chosen from one of the standard
  1877.                         rates 50, 110, 300, 600, 1200, 2400, 4800,
  1878.                         9600, 19200).
  1879.  
  1880. INKEY$ #stream          Returns a single character as a string if a
  1881.                         character is available, and returns the null
  1882.                         string "" if no character is available from
  1883.                         the stream.
  1884.  
  1885.                         This instruction is only meaningful if the
  1886.                         stream is linked to the network, or the RS232
  1887.                         Interface.
  1888.  
  1889. INPUT #stream;variable  Inputs the variable from the specified
  1890.                         stream. The stream must previously have been
  1891.                         opened to an input channel. It is important to
  1892.                         note that any print items in the INPUT
  1893.                         statement will be output to the stream. This
  1894.                         is usually only required when inputting from
  1895.                         the keyboard. It should also be noted that
  1896.                         the "," separator outputs a character.
  1897.  
  1898.                         The LINE option in available as before.
  1899.  
  1900. LOAD *channel options   Loads the program, data or code from the
  1901.                         specified channel. Only the channels "b", "n"
  1902.                         or "m" may be used.
  1903.  
  1904.                         All the options available with LOAD are
  1905.                         available with LOAD *.
  1906.  
  1907. MERGE *channel options  The same as LOAD above except that it does not
  1908.                         delete old program lines or variables except
  1909.                         to make way for new ones with the same line
  1910.                         number or name.
  1911.  
  1912. MOVE source TO          Moves data from the source to the
  1913. destination             destination. The source and destination may be
  1914.                         either stream numbers or channels.
  1915.  
  1916.                         The command only terminates when an end of
  1917.                         file marker is encountered in the source: this
  1918.                         can only happen if the source is either a
  1919.                         network or Microdrive channel or else a stream
  1920.                         linked to one.
  1921.  
  1922.                         If the source or destination is a channel then
  1923.                         it is effectively opened first and closed
  1924.                         afterwards.
  1925.  
  1926. OPEN #stream, channel   Links the specified channel to the specified
  1927.                         stream in order to allow BASIC input or output
  1928.                         to that channel. The stream must previously be
  1929.                         closed or opened to k, s or p.
  1930.  
  1931. PRINT #stream...        Outputs the print sequence (...) to the
  1932.                         specified stream. The stream must previously
  1933.                         have been opened to an output channel.
  1934.  
  1935. SAVE *channel options   Saves the program, data or code to the
  1936.                         specified channel. Only the channels "b", "n"
  1937.                         or "m" may be used.
  1938.  
  1939.                         All the options available with SAVE are
  1940.                         available with SAVE *.
  1941.  
  1942. VERIFY *channel options The same as LOAD above except the data is not
  1943.                         loaded but is compared with data already
  1944.                         there.
  1945.